﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;

using MobileGIS.Carto;
namespace MobileGIS.Data
{
    public class ShapefileWorkspace:IWorkspace,IFeatureWorkspace
    {
        private IWorkspaceFactory m_fact = null;

        #region IWorkspace Members

        public IWorkspaceFactory WorkspaceFactory
        {
            get { return m_fact;  }
            internal set { m_fact = value; }
        }

        public void ExecuteSQL(string sql)
        {
            throw new NotImplementedException();
        }

        public bool Exists()
        {
            if (this.IsDirectory())
                return true;
            else
                return false;
        }

        public bool IsDirectory()
        {
            try
            {
                if (System.IO.Directory.Exists(this.PathName))
                    return true;
                else
                    return false;
            }
            catch 
            {
                return false;
            }
        }

        public string PathName
        {
            get;
            internal set;
        }

        #endregion

        #region IFeatureWorkspace Members

        public MobileGIS.Carto.IFeatureClass OpenFeatureClass(string Name)
        {
            string shpfilepath = this.PathName + "\\" + Name + ".shp";
            string dbfilepath = this.PathName + "\\" + Name + ".dbf";
            IntPtr hSHP = MobileGIS.ShapeLibCE.SHPOpen(shpfilepath, "rb");
            int nCount = -1;
            MobileGIS.ShapeLibCE.ShapeType type = ShapeLibCE.ShapeType.NullShape;
            MobileGIS.ShapeLibCE.SHPGetInfo(hSHP, ref nCount, ref type, null, null );

            FeatureClass ftrClass = new FeatureClass();
            //ftrClass.FeatureClassType = FeatureClassType.ShapeLayer;
            //ftrClass.GeometryType = MobileGIS.Geometries.GeometryType.Point;
            

            


            throw new NotImplementedException();
        }

        public MobileGIS.Carto.IFeatureClass CreateFeatureClass()
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
